<html>

<head>
  <script>
    function myFunc() {
      document.write(a);
      document.write(func());
      var a = 1;
      function func() {
        return 2;
      }
    }
  </script>
</head>

<body>
  <p>1</p>
  <button onclick="myFunc()">点击</button>
</body>

</html>